<template>
  <el-dialog
    :title="!dataForm.id ? '子订单详情' : '子订单详情'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="订单编号" prop="orderId">
      <el-input v-model="dataForm.orderId" placeholder="订单编号"></el-input>
    </el-form-item>
    <el-form-item label="商家名称" prop="storeName">
      <el-input v-model="dataForm.storeName" placeholder="商家名称"></el-input>
    </el-form-item>
    <el-form-item label="买家名称" prop="trueName">
      <el-input v-model="dataForm.userName" placeholder="买家名称" v-if="dataForm.usertype == 3"></el-input>
      <el-input v-model="dataForm.trueName" placeholder="买家名称" v-if="dataForm.usertype != 3"></el-input>
    </el-form-item>
    <el-form-item label="商品名称" prop="goodsTitle">
      <el-input v-model="dataForm.goodsTitle" placeholder="商品名称"></el-input>
    </el-form-item>
    <!-- <el-form-item label="商品主图片" prop="img">
      <el-upload
      action=""
      disabled="true"
      list-type="picture-card"
      :file-list="dataForm.img"
      :on-preview="handlePreview">
      <i class="el-icon-plus"></i>
      </el-upload> -->
      <!-- <el-input v-model="dataForm.img" placeholder="商品主图片"></el-input> -->
    <!-- </el-form-item> -->
    <el-form-item label="商品单价" prop="goodsPrice">
      <el-input v-model="dataForm.goodsPrice" placeholder="商品单价"></el-input>
    </el-form-item>
    <el-form-item label="商品规格" prop="goodsSpecifications">
      <el-input v-model="dataForm.goodsSpecifications" placeholder="商品规格"></el-input>
    </el-form-item>
    <el-form-item label="商品数量" prop="goodsCount">
      <el-input v-model="dataForm.goodsCount" placeholder="商品数量"></el-input>
    </el-form-item>
    <el-form-item label="总金额" prop="goodsTotalMoney">
      <el-input v-model="dataForm.goodsTotalMoney" placeholder="总金额"></el-input>
    </el-form-item>
    <el-form-item label="商品描述" prop="goodsDetails">
      <el-input v-model="dataForm.goodsDetails" placeholder="商品描述"></el-input>
    </el-form-item>
    <el-form-item label="积分数量" prop="goodsCommission">
      <el-input v-model="dataForm.goodsCommission" placeholder="积分数量"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-date-picker v-model="dataForm.createTime" type="datetime" placeholder="创建时间" disabled></el-date-picker>
      <!-- <el-input v-model="dataForm.createtime" placeholder="下单时间"></el-input> -->
    </el-form-item>
    </el-form>
    <!-- <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span> -->
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dialogImageUrl: '',
        dialogVisible: false,
        dataForm: {
          storeimage: [],
          id: 0,
          orderId: '',
          storeName: '',
          trueName: '',
          username: '',
          userType: '',
          goodsTitle: '',
          img: '',
          goodsPrice: '',
          goodsSpecifications: '',
          goodsCount: '',
          goodsTotalaMoney: '',
          goodsDetails: '',
          goodsCommission: '',
          createTime: ''
        },
        dataRule: {
          orderno: []
        }
      }
    },
    methods: {
      // 图片预览
      handlePreview (file) {
        this.dialogImageUrl = file.url
        this.dialogVisible = true
      },
      init (id) {
        this.dataForm.orderid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.orderid) {
            var map = {'id1': id}
            this.$http({
              url: this.$http.adornUrl(`/business/order/getOrderByPayNO`),
              method: 'get',
              params: this.$http.adornParams(map, false)
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.orderId = data.data.orderId
                this.dataForm.storeName = data.data.storeName
                this.dataForm.trueName = data.data.trueName
                this.dataForm.username = data.data.username
                this.dataForm.userType = data.data.userType
                this.dataForm.goodsTitle = data.data.goodsTitle
                this.dataForm.img = data.data.img
                this.dataForm.goodsPrice = data.data.goodsPrice
                this.dataForm.goodsSpecifications = data.data.goodsSpecifications
                this.dataForm.goodsCount = data.data.goodsCount
                this.dataForm.goodsTotalaMoney = data.data.goodsTotalaMoney
                this.dataForm.goodsDetails = data.data.goodsDetails
                this.dataForm.goodsCommission = data.data.goodsCommission
                this.dataForm.createTime = data.data.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/business/order/${!this.dataForm.orderid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'orderid': this.dataForm.orderid || undefined,
                'orderno': this.dataForm.orderno,
                'userid': this.dataForm.userid,
                'orderstatus': this.dataForm.orderstatus,
                'totalmoney': this.dataForm.totalmoney,
                'goodscount': this.dataForm.goodscount,
                'delivermoney': this.dataForm.delivermoney,
                'paytype': this.dataForm.paytype,
                'ispay': this.dataForm.ispay,
                'shopid': this.dataForm.shopid,
                'orderremarks': this.dataForm.orderremarks,
                'createtime': this.dataForm.createtime,
                'orderunique': this.dataForm.orderunique,
                'ordersrc': this.dataForm.ordersrc,
                'orderflag': this.dataForm.orderflag,
                'tradeno': this.dataForm.tradeno,
                'payfrom': this.dataForm.payfrom,
                'couponmoney': this.dataForm.couponmoney,
                'confimtime': this.dataForm.confimtime,
                'sucesstime': this.dataForm.sucesstime,
                'buyuserid': this.dataForm.buyuserid,
                'goodsids': this.dataForm.goodsids,
                'storeiphone': this.dataForm.storeiphone,
                'storename': this.dataForm.storename,
                'storeimage': this.dataForm.storeimage,
                'addresstext': this.dataForm.addresstext,
                'marketprice': this.dataForm.marketprice,
                'vipprice': this.dataForm.vipprice,
                'iscommission': this.dataForm.iscommission,
                'commission': this.dataForm.commission,
                'coupons': this.dataForm.coupons,
                'distributiontype': this.dataForm.distributiontype,
                'addressid': this.dataForm.addressid,
                'operationtime': this.dataForm.operationtime,
                'appointmenttime': this.dataForm.appointmenttime,
                'shelvestime': this.dataForm.shelvestime,
                'lngandlat': this.dataForm.lngandlat
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
